﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace myMoney.File
{
    public partial class ucChangePass : UserControl
    {
        public ucChangePass()
        {
            InitializeComponent();
            this.lblUserID.Text = Main.CurrentUser;
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            this.gbPass.Location = new Point((this.Width - this.gbPass.Width) / 2, (this.Height - this.gbPass.Height) / 4);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //if (this.tbOpass.Text.Length == 0)
            //{
            //    MessageBox.Show("请输入旧密码");
            //    return;
            //}
            if (this.tbNpass.Text.Length == 0)
            {
                MessageBox.Show("请输入新密码");
                return;
            }
            if (this.tbNpass.Text != this.tbConfirmNpass.Text)
            {
                MessageBox.Show("两次输入密码不一致");
                return;
            }

            try
            {
                int rval = MoneyClass.User.Update(Main.CurrentGuid, QT.Tools.MD5(this.tbNpass.Text), QT.Tools.MD5(this.tbOpass.Text));
                if (rval == 0) MessageBox.Show("旧密码错误");
                else MessageBox.Show("操作成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show("操作失败："+ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
